/*
 *    Copyright (c) 2018-2025, proj All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * Redistributions of source code must retain the above copyright notice,
 * this list of conditions and the following disclaimer.
 * Redistributions in binary form must reproduce the above copyright
 * notice, this list of conditions and the following disclaimer in the
 * documentation and/or other materials provided with the distribution.
 * Neither the name of the proj developer nor the names of its
 * contributors may be used to endorse or promote products derived from
 * this software without specific prior written permission.
 * Author: proj
 */
package com.ykht.proj.coupon.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.ykht.proj.common.core.util.R;
import com.ykht.proj.common.security.util.SecurityUtils;
import com.ykht.proj.coupon.Enum.CommissionType;
import com.ykht.proj.coupon.Enum.DistributionTypeEnum;
import com.ykht.proj.coupon.Enum.RuleTypeEnum;
import com.ykht.proj.coupon.Enum.TaskTypeEnum;
import com.ykht.proj.coupon.entity.*;
import com.ykht.proj.coupon.mapper.*;
import com.ykht.proj.coupon.service.CnBrandService;
import com.ykht.proj.coupon.service.FxConfRewardService;
import com.ykht.proj.coupon.vo.ConfRewardShopVo;
import com.ykht.proj.coupon.vo.FxConfRewardVO;
import lombok.extern.slf4j.Slf4j;
import org.bouncycastle.crypto.params.CCMParameters;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.*;
import java.util.stream.Collectors;

/**
 * 品牌邀请、转发、核销配置表
 *
 * @author proj code generator
 * @date 2021-02-01 19:00:18
 */
@Slf4j
@Service
@Transactional
public class FxConfRewardServiceImpl extends ServiceImpl<FxConfRewardMapper, FxConfReward> implements FxConfRewardService {

	@Resource
	private CnShopMapper cnShopMapper;
	@Resource
	private FxConfRewardMapper fxConfRewardMapper;
	@Resource
	private FxConfShopMapper fxConfShopMapper;
	@Resource
	private FxConfRewardBaseGlobelMapper fxConfRewardBaseGlobelMapper;

	@Override
	public IPage<FxConfRewardVO> queryByPage(Page page, FxConfRewardVO fxConfRewardVO) {
		IPage<FxConfRewardVO> iPage = new Page<>(page.getCurrent(), page.getSize());
		IPage<FxConfRewardVO> result = this.baseMapper.queryByPage(iPage, fxConfRewardVO);
		/*查询完之后进行二次封装*/
		for (int i = 0; i < result.getRecords().size(); i++) {
			if (result.getRecords().get(i).getRewardType().equals(CommissionType.REWARD_TYPE_0.getValue())) {
				result.getRecords().get(i).setRewardTypeName(CommissionType.REWARD_TYPE_0.getDesc());
			}
			if (result.getRecords().get(i).getRewardType().equals(CommissionType.REWARD_TYPE_1.getValue())) {
				result.getRecords().get(i).setRewardTypeName(CommissionType.REWARD_TYPE_1.getDesc());
			}
			/*优美的分隔符*/
			if (result.getRecords().get(i).getRuleType().equals(DistributionTypeEnum.DISTRIBUTION_TYPE_0.getValue())) {
				result.getRecords().get(i).setFenXiaoName(DistributionTypeEnum.DISTRIBUTION_TYPE_0.getDesc());
			}
			if (result.getRecords().get(i).getRuleType().equals(DistributionTypeEnum.DISTRIBUTION_TYPE_1.getValue())) {
				result.getRecords().get(i).setFenXiaoName(DistributionTypeEnum.DISTRIBUTION_TYPE_1.getDesc());
			}
			if (result.getRecords().get(i).getRuleType().equals(DistributionTypeEnum.DISTRIBUTION_TYPE_2.getValue())) {
				result.getRecords().get(i).setFenXiaoName(DistributionTypeEnum.DISTRIBUTION_TYPE_2.getDesc());
			}
			if (result.getRecords().get(i).getRuleType().equals(DistributionTypeEnum.DISTRIBUTION_TYPE_3.getValue())) {
				result.getRecords().get(i).setFenXiaoName(DistributionTypeEnum.DISTRIBUTION_TYPE_3.getDesc());
			}
			if (result.getRecords().get(i).getRuleType().equals(DistributionTypeEnum.DISTRIBUTION_TYPE_4.getValue())) {
				result.getRecords().get(i).setFenXiaoName(DistributionTypeEnum.DISTRIBUTION_TYPE_4.getDesc());
			}
//			for (int j = 0; j < result.getRecords().size(); j++) {
//				//比较出来重复的门店
//				if(result.getRecords().get(i).getShopId().equals(result.getRecords().get(j).getShopId())){
//					//根据优先级删除
//					if(result.getRecords().get(i).getRewardType().equals(FenXiaoType.FEN_XIAO_TYPE_1.getValue())){
//						list.add(result.getRecords().get(i));
//						continue;
//					}
//					if(result.getRecords().get(i).getRewardType().equals(FenXiaoType.FEN_XIAO_TYPE_2.getValue())){
//						list.add(result.getRecords().get(i));
//						continue;
//					}
//					if(result.getRecords().get(i).getRewardType().equals(FenXiaoType.FEN_XIAO_TYPE_3.getValue())){
//						list.add(result.getRecords().get(i));
//						continue;
//					}
//					if(result.getRecords().get(i).getRewardType().equals(FenXiaoType.FEN_XIAO_TYPE_4.getValue())){
//						list.add(result.getRecords().get(i));
//						continue;
//					}
//					if(result.getRecords().get(i).getRewardType().equals(FenXiaoType.FEN_XIAO_TYPE_5.getValue())){
//						list.add(result.getRecords().get(i));
//						continue;
//					}
//				}
//				list.add(result.getRecords().get(i));
//			}
		}
		return result;
	}

	@Override
	public List<FxConfRewardVO> findById(Long shopId) {
		List<FxConfRewardVO> record = this.baseMapper.findById(shopId);
		for (FxConfRewardVO fxConfReward : record) {
//				fxConfReward.setId(fxConfRewardVO.getId());
//				fxConfReward.setBrandName(fxConfRewardVO.getBrandName());
//				fxConfReward.setBrandId(fxConfRewardVO.getBrandId());
//				fxConfReward.setShopName(fxConfRewardVO.getShopName());
//				fxConfReward.setShopId(fxConfRewardVO.getShopId());
			if (fxConfReward.getRuleType() != null) {
				if (fxConfReward.getRuleType().equals(DistributionTypeEnum.DISTRIBUTION_TYPE_0.getValue())) {
					fxConfReward.setFenXiaoName(DistributionTypeEnum.DISTRIBUTION_TYPE_0.getDesc());
//						map.put("注册", fxConfReward);
				}
				if (fxConfReward.getRuleType().equals(DistributionTypeEnum.DISTRIBUTION_TYPE_1.getValue())) {
					fxConfReward.setFenXiaoName(DistributionTypeEnum.DISTRIBUTION_TYPE_1.getDesc());
//						map.put("转发", fxConfReward);
				}
				if (fxConfReward.getRuleType().equals(DistributionTypeEnum.DISTRIBUTION_TYPE_2.getValue())
				) {
					fxConfReward.setFenXiaoName(DistributionTypeEnum.DISTRIBUTION_TYPE_2.getDesc());
//							map.put("核销-满减", fxConfReward);
				}
			}
			if (fxConfReward.getRuleType().equals(DistributionTypeEnum.DISTRIBUTION_TYPE_3.getValue())) {
				fxConfReward.setFenXiaoName(DistributionTypeEnum.DISTRIBUTION_TYPE_3.getDesc());
//						map.put("关注", fxConfReward);
			}
			if
			(fxConfReward.getRuleType().equals(DistributionTypeEnum.DISTRIBUTION_TYPE_4.getValue())) {
				fxConfReward.setFenXiaoName(DistributionTypeEnum.DISTRIBUTION_TYPE_4.getDesc());
//						map.put("收藏", fxConfReward);
			}
		}
		return record;
	}

	@Override
	public IPage<FxConfRewardVO> findListById(Page page, FxConfRewardVO fxConfRewardVO) {
		Integer[] array = this.baseMapper.queryRewardIdByShopId(fxConfRewardVO.getShopId());
		IPage<FxConfRewardVO> iPage = new Page<>(page.getCurrent(), page.getSize());
		IPage<FxConfRewardVO> result = this.baseMapper.findListById(iPage, array, fxConfRewardVO);
		for (FxConfRewardVO record : result.getRecords()) {
			if (record.getStatus().equals(0L)) {
				record.setStatusName("上架/" + record.getRemark());
			} else {
				record.setStatusName("下架/" + record.getRemark());
			}
			if (record.getRewardType().equals(CommissionType.REWARD_TYPE_0.getValue())) {
				record.setRewardTypeName(CommissionType.REWARD_TYPE_0.getDesc());
			} else if (record.getRewardType().equals(CommissionType.REWARD_TYPE_1.getValue())) {
				record.setRewardTypeName(CommissionType.REWARD_TYPE_1.getDesc());
			}
			if (record.getRuleType() != null) {
				if (record.getRuleType().equals(DistributionTypeEnum.DISTRIBUTION_TYPE_0.getValue())) {
					record.setFenXiaoName(DistributionTypeEnum.DISTRIBUTION_TYPE_0.getDesc());
				} else if (record.getRuleType().equals(DistributionTypeEnum.DISTRIBUTION_TYPE_1.getValue())) {
					record.setFenXiaoName(DistributionTypeEnum.DISTRIBUTION_TYPE_1.getDesc());
				} else if (record.getRuleType().equals(DistributionTypeEnum.DISTRIBUTION_TYPE_2.getValue())) {
					record.setFenXiaoName(DistributionTypeEnum.DISTRIBUTION_TYPE_2.getDesc());
				} else if (record.getRuleType().equals(DistributionTypeEnum.DISTRIBUTION_TYPE_3.getValue())) {
					record.setFenXiaoName(DistributionTypeEnum.DISTRIBUTION_TYPE_3.getDesc());
				} else if (record.getRuleType().equals(DistributionTypeEnum.DISTRIBUTION_TYPE_4.getValue())) {
					record.setFenXiaoName(DistributionTypeEnum.DISTRIBUTION_TYPE_4.getDesc());
				}
			}
			if (record.getTask() != null) {
				if (record.getTask().equals(TaskTypeEnum.TASK_TYPE_0.getValue())) {
					record.setTaskName(TaskTypeEnum.TASK_TYPE_0.getDesc());
				} else if (record.getTask().equals(TaskTypeEnum.TASK_TYPE_1.getValue())) {
					record.setTaskName(TaskTypeEnum.TASK_TYPE_1.getDesc());
				} else if (record.getTask().equals(TaskTypeEnum.TASK_TYPE_2.getValue())) {
					record.setTaskName(TaskTypeEnum.TASK_TYPE_2.getDesc());
				}
			}
		}
		return result;
	}

	@Override
	public Object insert(FxConfRewardVO fxConfRewardVO) {
		if (fxConfRewardVO.getPercent() != null) {
			fxConfRewardVO.setRewardType(CommissionType.REWARD_TYPE_1.getValue());
		} else if (fxConfRewardVO.getBaseMoney() != null) {
			fxConfRewardVO.setRewardType(CommissionType.REWARD_TYPE_0.getValue());
		}
		fxConfRewardVO.setBrandId(fxConfRewardVO.getBrandId());
		fxConfRewardVO.setUpdateTime(LocalDateTime.now());
		fxConfRewardVO.setCreateTime(LocalDateTime.now());
		this.baseMapper.insert(fxConfRewardVO);
		String[] arr = fxConfRewardVO.getShopNameList().split(",");
		for (String s : arr) {
			FxConfShop fxConfShop = new FxConfShop();
			fxConfShop.setConfRewardId(fxConfRewardVO.getId());
			fxConfShop.setShopId(Long.parseLong(s));
			CnShop cnShop = cnShopMapper.selectById(Long.parseLong(s));
			fxConfShop.setBrandId(cnShop.getBrandId());
			fxConfShop.setCreateTime(LocalDateTime.now());
			fxConfShop.setUpdateTime(LocalDateTime.now());
			fxConfShopMapper.insert(fxConfShop);
		}
		return null;
	}

	@Override
	public Object updateConf(List<FxConfRewardVO> fxConfRewardVo) {
    	/*
    	根据分销任务去查询之前是否有已上架的所属门店的自定义配置
    	如果有就去将门店的自定义配置进行删除
    	新增一套自定义配置并上架
    	添加门店及品牌至改自定义配置
    	如果选择了最低限制 就把所有该门店的自定义的配置删除
    	* */
//		for (FxConfRewardVO confReward : fxConfRewardVo) {
//			confReward.setUpdateTime(LocalDateTime.now());
//			confReward.setUpdateUser(SecurityUtils.getUserId());
//			if (confReward.getIsDefaultConf() != null) {
//				if (confReward.getIsDefaultConf().equals(0)) {
//					this.baseMapper.updateDelflagByShopId(confReward.getShopId());
//					break;
//				}
//			}
//			Long id = this.baseMapper.queryValueByRuletype(confReward.getRuleType());
//			if (id != null) {
//				this.baseMapper.updateDelflagById(id);
//			}
//			this.baseMapper.insertValue(confReward);
//			FxConfShop fxConfShop = new FxConfShop();
//			fxConfShop.setShopId(confReward.getShopId());
//			fxConfShop.setBrandId(confReward.getBrandId());
//			fxConfShop.setConfRewardId(confReward.getId());
//			fxConfShopMapper.insert(fxConfShop);
//		}
		/*获取平台最低配置*/
		FxConfRewardBaseGlobel fxConfRewardBaseGlobel = fxConfRewardBaseGlobelMapper.selectOne(Wrappers.lambdaQuery(FxConfRewardBaseGlobel.class)
				.eq(FxConfRewardBaseGlobel::getDelFlag, 0)
				.eq(FxConfRewardBaseGlobel::getSwitchs, 0)
		);
		/*
		 * 1.首先将门店从配置中删除 但是有的门店并未进行过配置 那么直接跳过
		 * 2.然后新增一条配置
		 * 3.新增配置门店 并绑定配置的id
		 * */
		for (FxConfRewardVO list : fxConfRewardVo) {
			FxConfShop one = fxConfShopMapper.selectOne(Wrappers.lambdaQuery(FxConfShop.class)
					.eq(FxConfShop::getDelFlag, 0)
					.eq(FxConfShop::getConfRewardId, list.getId())
					.eq(FxConfShop::getShopId,list.getShopId())
					.eq(FxConfShop::getBrandId,list.getBrandId())
			);
			//有门店存在于配置之中 需要删除配置门店
			if (one != null) {
				//删除门店
//				fxConfShopMapper.delByShopIdAndConfId(one.getShopId(), list.getId());
				fxConfShopMapper.delete(Wrappers.lambdaQuery(FxConfShop.class).eq(FxConfShop::getConfRewardId,list.getId()).eq(FxConfShop::getShopId,one.getShopId()));
				//如果是最后一个门店就下架整个配置
				Integer count = fxConfShopMapper.selectCount(Wrappers.lambdaQuery(FxConfShop.class)
						.eq(FxConfShop::getConfRewardId, one.getConfRewardId())
						.eq(FxConfShop::getDelFlag, 0)
				);
				if (count == 0) {
					FxConfReward result = new FxConfReward();
					result.setStatus(1L);
					result.setId(one.getConfRewardId());
					log.info("->当前门店是配置中的最后一个，删除门店及下架配置{}",list);
					fxConfRewardMapper.updateById(result);
				}
				//修改配置列表时间
				FxConfReward fxConfReward = new FxConfReward();
				fxConfReward.setUpdateUser(SecurityUtils.getUserId());
				fxConfReward.setUpdateTime(LocalDateTime.now());
				fxConfReward.setId(one.getId());
				fxConfRewardMapper.updateById(fxConfReward);
			}
			//未有门店存在于配置之中 无需删除配置门店
			//进行下一步操作 新增配置
			FxConfReward fxConfReward = new FxConfReward();
			fxConfReward.setStatus(0L);
			fxConfReward.setCreateTime(LocalDateTime.now());
			fxConfReward.setCreateUser(SecurityUtils.getUserId());
			fxConfReward.setBrandId(list.getBrandId());
			fxConfReward.setRuleType(list.getRuleType());
			fxConfReward.setRewardType(list.getRewardType());
			if (list.getCouponType() != null) {
				fxConfReward.setCouponType(list.getCouponType());
			}
			//如果选择了最低配置
			if (list.getIsDefaultConf().equals(0)) {
				//根据分销任务类型来判断佣金

				//核销
				if (list.getRuleType().equals(DistributionTypeEnum.DISTRIBUTION_TYPE_2.getValue())) {
					//判断是百分比还是固定金额
					if (list.getRewardType().equals(CommissionType.REWARD_TYPE_0.getValue())) {
						fxConfReward.setBaseMoney(fxConfRewardBaseGlobel.getUseCouponMoney());
					} else {
						fxConfReward.setPercent(fxConfRewardBaseGlobel.getUseCouponPercent());
					}
					//邀请
				} else if (list.getRuleType().equals(DistributionTypeEnum.DISTRIBUTION_TYPE_0.getValue())) {
					fxConfReward.setBaseMoney(fxConfRewardBaseGlobel.getInviteMoney());
					//转发
				} else if (list.getRuleType().equals(DistributionTypeEnum.DISTRIBUTION_TYPE_1.getValue())) {
					fxConfReward.setBaseMoney(fxConfRewardBaseGlobel.getForwardArticleMoney());
					//关注
				} else if (list.getRuleType().equals(DistributionTypeEnum.DISTRIBUTION_TYPE_3.getValue())) {
					fxConfReward.setBaseMoney(fxConfRewardBaseGlobel.getAttentionBrand());
					//收藏
				} else if (list.getRuleType().equals(DistributionTypeEnum.DISTRIBUTION_TYPE_4.getValue())) {
					fxConfReward.setBaseMoney(fxConfRewardBaseGlobel.getCollectShop());
				}
				fxConfReward.setRemark("最低限制");
			}else {
				fxConfReward.setRemark("自定义配置");
				//判断是百分比还是固定金额
				if (list.getRewardType().equals(CommissionType.REWARD_TYPE_0.getValue())) {
					fxConfReward.setBaseMoney(list.getBaseMoney());
				} else {
					fxConfReward.setPercent(list.getPercent());
				}
			}
			//如果未选择最低配置责任自定义佣金走

			//添加新的配置记录
			fxConfRewardMapper.insert(fxConfReward);
			//添加配置门店记录
			//拿到返回的配置ID
			Long confRewardId = fxConfReward.getId();
			FxConfShop fxConfShop = new FxConfShop();
			fxConfShop.setCreateTime(LocalDateTime.now());
			fxConfShop.setCreateUser(SecurityUtils.getUserId());
			fxConfShop.setBrandId(list.getBrandId());
			fxConfShop.setShopId(list.getShopId());
			fxConfShop.setConfRewardId(confRewardId);
			fxConfShopMapper.insert(fxConfShop);
		}
		return null;
	}

	@Override
	public Object findShopAndBrand(Long shopId) {
		return this.baseMapper.findShopAndBrand(shopId);
	}

	@Override
	public List<FxConfRewardVO> findConfReward(FxConfRewardVO fxConfRewardVO, CnBrand cnBrand) {
		List<FxConfRewardVO> resultList = this.baseMapper.findConfReward(fxConfRewardVO, cnBrand);
		for (FxConfRewardVO record : resultList) {
			if (record.getRuleType() != null) {
				if (record.getRuleType().equals(DistributionTypeEnum.DISTRIBUTION_TYPE_0.getValue())) {
					record.setFenXiaoName(DistributionTypeEnum.DISTRIBUTION_TYPE_0.getDesc());
				} else if (record.getRuleType().equals(DistributionTypeEnum.DISTRIBUTION_TYPE_1.getValue())) {
					record.setFenXiaoName(DistributionTypeEnum.DISTRIBUTION_TYPE_1.getDesc());
				} else if (record.getRuleType().equals(DistributionTypeEnum.DISTRIBUTION_TYPE_2.getValue())) {
					record.setFenXiaoName(DistributionTypeEnum.DISTRIBUTION_TYPE_2.getDesc());
				} else if (record.getRuleType().equals(DistributionTypeEnum.DISTRIBUTION_TYPE_3.getValue())) {
					record.setFenXiaoName(DistributionTypeEnum.DISTRIBUTION_TYPE_3.getDesc());
				} else if (record.getRuleType().equals(DistributionTypeEnum.DISTRIBUTION_TYPE_4.getValue())) {
					record.setFenXiaoName(DistributionTypeEnum.DISTRIBUTION_TYPE_4.getDesc());
				}
			}
			if (record.getRewardType().equals(CommissionType.REWARD_TYPE_0.getValue())) {
				record.setRewardTypeName(CommissionType.REWARD_TYPE_0.getDesc());
			} else if (record.getRewardType().equals(CommissionType.REWARD_TYPE_1.getValue())) {
				record.setRewardTypeName(CommissionType.REWARD_TYPE_1.getDesc());
			}
		}
		return resultList;
	}

	@Override
	public Object updateConfReward(FxConfRewardVO fxConfRewardVo, CnBrand cnBrand) {
		FxConfReward fxConfReward = new FxConfReward();
		fxConfReward.setId(fxConfRewardVo.getId());
		fxConfReward.setStatus(fxConfRewardVo.getStatus());
		fxConfReward.setRewardType(fxConfRewardVo.getRewardType());
		fxConfReward.setBaseMoney(fxConfRewardVo.getBaseMoney());
		fxConfReward.setPercent(fxConfRewardVo.getPercent());
		fxConfReward.setBrandId(cnBrand.getId());
		fxConfReward.setCreateTime(LocalDateTime.now());
		fxConfReward.setCreateUser(SecurityUtils.getUserId());
		fxConfReward.setRemark("自定义配置");
		fxConfReward.setRuleType(fxConfRewardVo.getRuleType());
		fxConfReward.setCouponType(fxConfRewardVo.getCouponType());
		String[] split = fxConfRewardVo.getShopIdList().split(",");
		//将之前的配置删除
		this.baseMapper.updateAllConfShop(fxConfRewardVo.getId());
		fxConfRewardVo.setUpdateUser(SecurityUtils.getUserId());
		fxConfRewardVo.setUpdateTime(LocalDateTime.now());
		//将配置的门店删除
		fxConfShopMapper.delConfById(fxConfRewardVo);
		//新增一条配置
		this.baseMapper.insert(fxConfReward);
		//新增配置门店
		for (String s : split) {
			FxConfShop fxConfShop = new FxConfShop();
			fxConfShop.setBrandId(fxConfRewardVo.getBrandId());
			fxConfShop.setShopId(cnBrand.getId());
			fxConfShop.setConfRewardId(fxConfRewardVo.getId());
			fxConfShop.setCreateUser(SecurityUtils.getUserId());
			fxConfShop.setCreateTime(LocalDateTime.now());
			fxConfShop.setShopId(Long.parseLong(s));
			fxConfShop.setConfRewardId(fxConfReward.getId());
			fxConfShopMapper.insert(fxConfShop);
		}

//
//
//		List<Long> shopIdList = null;
//		/*
//		* 111 112
//		* 113
//		* */
//		if (split.length == 1) {
//			shopIdList = fxConfShopMapper.selectShopId(fxConfRewardVo);
//			if (Long.parseLong(split[0]) != (shopIdList.get(0))) {
//				this.baseMapper.updateAllConfShop(fxConfRewardVo.getId());
//			} else {
//				//		找寻到添加配置的门店
//				shopIdList = fxConfShopMapper.selectShopId(fxConfRewardVo);
//			}
//		} else {
//			shopIdList = fxConfShopMapper.selectShopId(fxConfRewardVo);
//		}
//		if (fxConfReward.getRuleType() != null || fxConfReward != null || fxConfReward.getRewardType() != null || fxConfReward.getPercent() != null || fxConfReward.getStatus() != null) {
//			this.baseMapper.updateById(fxConfReward);
//		}
//		/*修改表中被删除的门店id*/
//		fxConfShopMapper.updateShop(fxConfRewardVo.getId(), split);
//		/*修改完配置之后需要对适用的门店进行修改
//		 * 先判断是否是增加了门店
//		 * 如果这条配置相较之前少了门店就删除门店
//		 * 如果这条配置相较之前增了门店就添加门店
//		 * */
//		List<Long> resultList = new ArrayList<Long>();
//		for (String s : split) {
//			resultList.add(Long.parseLong(s));
//		}
////		resultList.removeAll(shopIdList);
//		//如果当前查询的配置长度不符合已存在的配置就进行新增
//		if (shopIdList.size() > 0) {
//			List<Long> idList = cnShopMapper.findByIds(shopIdList, fxConfRewardVo);
//			if (idList.size() > 0) {
//				//对传入的门店串 和 自查表中的门店串进行去重 获取到 新增的门店
//				for (int i = 0; i < idList.size(); i++) {
//					for (int j = 0; j < resultList.size(); j++) {
//						System.out.println(idList.get(i) + "-" + resultList.get(j));
//						if (idList.get(i).equals(resultList.get(j))) {
//							FxConfShop fxConfShop = new FxConfShop();
//							fxConfShop.setBrandId(fxConfRewardVo.getBrandId());
//							fxConfShop.setShopId(resultList.get(j));
//							fxConfShop.setConfRewardId(fxConfRewardVo.getId());
//							fxConfShop.setCreateUser(SecurityUtils.getUserId());
//							fxConfShop.setCreateTime(LocalDateTime.now());
//							fxConfShopMapper.insert(fxConfShop);
//						}
//					}
//				}
//			}
//		}
		return null;
	}

	@Override
	public Object delConfReward(Long id) {
		this.baseMapper.delById(id);
		fxConfShopMapper.deleteByConfId(id);
		return null;
	}

	@Override
	public ConfRewardShopVo getConfRewardShopVo(ConfRewardShopVo temp) {
		return fxConfRewardMapper.getConfRewardShopVo(temp);
	}

	@Override
	public Object queryAllShopByBrandId(CnBrand cnBrand, FxConfRewardVO fxConfRewardVO) {
		//拿到品牌下全部的门店
		List<Long> cnShops = this.baseMapper.queryAllShopByBrandId(cnBrand);
		//拿到全部配置过的门店
		List<Long> cnShops1 = this.baseMapper.queryAllShopByDelflag(cnBrand, fxConfRewardVO);
		cnShops.removeAll(cnShops1);
		if (cnShops.size() > 0) {
			List<CnShop> list = this.baseMapper.queryShopByIdList(cnShops);
			return list;
		} else {
			return null;
		}
	}

	@Override
	public Object updateShowHave(CnBrand cnBrand, String[] arr) {
		return this.baseMapper.updateShowHave(cnBrand, arr);
	}

	@Override
	public List<FxConfShop> judgeConfIsOk(CnBrand cnBrand, String[] arr, FxConfRewardVO fxConfRewardVO) {
		return this.baseMapper.judgeConfIsOk(cnBrand, arr, fxConfRewardVO);
	}

	@Override
	public void updateStatus() {
		this.baseMapper.updateStatus();
	}

	@Override
	public List<FxConfShop> judgeConf2IsOk(CnBrand cnBrand, String[] arr, FxConfRewardVO fxConfRewardVO) {
		return this.baseMapper.judgeConf2IsOk(cnBrand, arr, fxConfRewardVO);
	}

	@Override
	public Object getAllShopByBrandId(Object data, FxConfRewardVO fxConfRewardVO) {
		return null;
	}

	@Override
	public FxConfRewardVO findConfByBrandIdAndShopId(FxWaiterExt userExt, Integer fenXiaoType) {
		return this.baseMapper.findConfByBrandIdAndShopId(userExt, fenXiaoType);
	}
}
